/*
 * @Description: 更换npm私服组件
 * @Author: Liu Zhiwang
 * @Date: 2021-03-27 14:34:20
 * @LastEditTime: 2021-04-29 09:59:46
 * @LastEditors: Liu Zhiwang
 */
import './utils/rem.js' // rem布局设置引入
import './public-path'
import Vue from 'vue'
import Cookies from 'js-cookie'
import 'normalize.css/normalize.css' // a modern alternative to CSS resets
import Element from 'element-ui'
import './styles/element-variables.scss'
import './styles/gis-ui.scss' // gis css cover
import '@/styles/index.scss' // global css
import App from './App'
import store from './store'
import router from './router'
import './icons' // icon
import './permission' // permission control
import './utils/error-log' // error log
import './utils/public' // public method and config
import permissionButton from './directive/permission-button' // button permission
Vue.use(permissionButton)

// import components from '@/components'
// Vue.use(components)

import ItpsCommons from 'itps-commons'
import './styles/itps-commons.scss'
Vue.use(ItpsCommons)

import 'viewerjs/dist/viewer.css' // image preview
import Viewer from 'v-viewer'
Vue.use(Viewer, {
  defaultOptions: {
    zIndex: 9999,
    title: val => {
      return val.alt
    }
  }
})

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online! ! !
 */
import { mockXHR } from '../mock'
if (process.env.NODE_ENV === 'production') {
  mockXHR()
}
Vue.use(Element, {
  size: Cookies.get('size') || 'medium' // set element-ui default size
})

// 登录ArcGIS Server
// import { loginArcGISServer } from '@/utils/gis'
// loginArcGISServer()

Vue.config.productionTip = false

let instance = null

function render(props = {}) {
  // const { container, routerBase } = props
  // const router = new VueRouter({
  //   base: window.__POWERED_BY_QIANKUN__ ? routerBase : process.env.BASE_URL,
  //   mode: 'history',
  //   routes
  // })

  const { container } = props
  instance = new Vue({
    router,
    store,
    render: (h) => h(App)
  }).$mount(container ? container.querySelector('#app') : '#app')
}

if (!window.__POWERED_BY_QIANKUN__) {
  // 这里是子应用独立运行的环境，实现子应用的登录逻辑

  // 独立运行时，也注册一个名为global的store module
  // commonStore.globalRegister(store)
  // 模拟登录后，存储用户信息到global module
  // const userInfo = { name: '我是独立运行时名字叫张三' } // 假设登录后取到的用户信息
  // store.commit('global/setGlobalState', { user: userInfo })

  render()
}

export async function bootstrap() {
  console.log('[vue] vue app bootstraped')
}

export async function mount(props) {
  console.log('[vue] props from main framework', props)

  // commonStore.globalRegister(store, props)

  render(props)
}

export async function unmount() {
  instance.$destroy()
  instance.$el.innerHTML = ''
  instance = null
}

import phmTestData from '@/api/phm/demo/data.js'
Vue.prototype.PHMTESTDATA = phmTestData

import 'font-awesome/css/font-awesome.min.css'

// winglinks
import { getDicts } from '@/api/cms/winglinks/system/dict/data'
import DictData from '@/components/DictData'
import DictTag from '@/components/DictTag'
import ImagePreview from '@/components/ImagePreview'
import moment from 'moment'
Vue.component('DictTag', DictTag)
Vue.component('ImagePreview', ImagePreview)
Vue.prototype.getDicts = getDicts
DictData.install()
Vue.prototype.moment = moment

